
//
//  AddressTableViewCell.swift
//  OnceNectar
//
//  Created by 法正磊 on 2018/2/26.
//  Copyright © 2018年 com.inwhoop. All rights reserved.
//

import UIKit

protocol AddressTableViewCellDelegate: NSObjectProtocol {
    func eidtTap(cell: AddressTableViewCell)
    func deleteTap(cell: AddressTableViewCell)
    func defaultTap(cell: AddressTableViewCell)
}

class AddressTableViewCell: UITableViewCell {
    @IBOutlet weak var nameLabel: UILabel!
    @IBOutlet weak var phoneLabel: UILabel!
    @IBOutlet weak var addressLabel: UILabel!
    @IBOutlet weak var defaultButton: UIButton!
    weak var delegate: AddressTableViewCellDelegate?
    override func awakeFromNib() {
        super.awakeFromNib()
        setUI()
        // Initialization code
    }
    
    func setUI() {
      
    }
    
    func defaultButtonParam(model: AddressModel) {
        let isDefault = Int(model.isDefault!)!
        let title = isDefault > 0 ? "默认地址" : "设为默认"
        let color = isDefault > 0 ? ONColor.currencyRedColor : ONColor.unSelectColor
        defaultButton.layer.cornerRadius = defaultButton.height / 2
        defaultButton.layer.borderColor = color.cgColor
        defaultButton.setTitle(title, for: .normal)
        defaultButton.setTitleColor(color, for: .normal)
        defaultButton.layer.borderWidth = 1
        addressLabel.text = "\(model.province!)\(model.city!)\(model.county!)\(model.detailedAddress!)"
        nameLabel.text = model.name
        phoneLabel.text = model.mobile
    }

    // MARK: - 编辑
    @IBAction func eidtTap(_ sender: UIButton) {
        delegate?.eidtTap(cell: self)
    }
    // MARK: - 删除
    @IBAction func deleteTap(_ sender: UIButton) {
        delegate?.deleteTap(cell: self)
    }
    // MARK: - 默认
    @IBAction func defaultTap(_ sender: UIButton) {
        delegate?.defaultTap(cell: self)
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
